package com.solo.system.mapper;

import com.mybatisflex.core.query.QueryChain;
import com.mybatisflex.core.update.UpdateChain;
import com.solo.common.core.base.mapper.BasicMapper;
import com.solo.system.api.entity.SysRoleDept;
import org.apache.ibatis.annotations.Mapper;

import java.util.Collection;
import java.util.List;

import static com.solo.system.api.entity.table.SysRoleDeptTableDef.SysRoleDeptTable;

/**
 * 数据权限 Mapper
 * @author 十一
 * @since 2024-11-07 09:18
 * 人生若只如初见，何事秋风悲画扇
 **/
@Mapper
public interface SysRoleDeptMapper extends BasicMapper<SysRoleDept> {

    /**
     * 按角色id集合删除多条信息
     * @param roleIds 角色id集合
     * @return boolean
     */
    default boolean deleteByRoleIds(Collection<Long> roleIds) {
        return UpdateChain.of(this)
                .where(SysRoleDeptTable.RoleId.in(roleIds))
                .remove();
    }

    /**
     * 按角色id查询所属部门id集合
     * @param roleId 角色id
     * @return {@link List }<{@link Long }>
     */
    default List<Long> selectDeptIdsByRoleId(Long roleId) {
        return QueryChain.of(this)
                .select(SysRoleDeptTable.DeptId)
                .where(SysRoleDeptTable.RoleId.eq(roleId))
                .listAs(Long.class);
    }

}
